package com.sleepcamel.resteasyConfigurator.view.detail;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.wb.swt.SWTResourceManager;

import com.sleepcamel.rest.domain.Project;

public class ProjectDetailView extends DetailView<Project> {

	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	private Text nameTextField;
	private Text baseMappingTextField;
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ProjectDetailView(Composite parent, int style) {
		super(parent, SWT.NONE);
		setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite = formToolkit.createComposite(this, SWT.NONE);
		{
			TableWrapLayout twl_composite = new TableWrapLayout();
			twl_composite.numColumns = 2;
			composite.setLayout(twl_composite);
		}
		formToolkit.paintBordersFor(composite);
		
		Label lblNewLabel = formToolkit.createLabel(composite, "Name", SWT.NONE);
		lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		
		nameTextField = formToolkit.createText(composite, "", SWT.NONE);
		nameTextField.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
		nameTextField.setMessage("Project Name");
		
		Label lblNewLabel_2 = formToolkit.createLabel(composite, "Base Mapping", SWT.NONE);
		lblNewLabel_2.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		
		baseMappingTextField = formToolkit.createText(composite, "", SWT.NONE);
		baseMappingTextField.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP, 1, 1));
		baseMappingTextField.setMessage("Base Mapping");
	}
	
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = super.initDataBindings();
		//
		IObservableValue projectNameObserveValue = BeansObservables.observeValue(modelData, "name");
		IObservableValue txtNewText_1ObserveTextObserveWidget = SWTObservables.observeText(nameTextField, SWT.Modify);
		bindingContext.bindValue(txtNewText_1ObserveTextObserveWidget, projectNameObserveValue, null, null);
		//
		IObservableValue projectBaseMappingObserveValue = BeansObservables.observeValue(modelData, "baseMapping");
		IObservableValue txtNewText_3ObserveTextObserveWidget = SWTObservables.observeText(baseMappingTextField, SWT.Modify);
		bindingContext.bindValue(txtNewText_3ObserveTextObserveWidget, projectBaseMappingObserveValue, null, null);
		//
		return bindingContext;
	}
}
